package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.OrderHistoryHandler;
import com.cungmua.app.model.request.OrderHistoryRequest;
import com.cungmua.app.model.response.OrderHistoryResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/21/14.
 */
public class OrderHistoryTask extends AuthenticatedTask<OrderHistoryRequest,Void,OrderHistoryResponse> {
    private OrderHistoryHandler handler;
    private Context context;

    public OrderHistoryTask(OrderHistoryHandler handler, Context context) {
        this.handler = handler;
        this.context = context;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected OrderHistoryResponse doInBackground() throws RetrofitError {
        OrderHistoryRequest request=params[0];
        return CungMuaAPI.getService().getListOrderHistories(request.toFieldMap());
    }

    @Override
    protected void onSuccess(OrderHistoryResponse orderHistoryResponse) {
        handler.onListOrderHistories(orderHistoryResponse);
    }
}

